package com.cs.system.controller;

import com.cs.core.util.ParamUtil;
import com.cs.framework.common.HttpCode;
import com.cs.framework.domain.PageVO;
import com.cs.framework.domain.R;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.cs.system.entity.SysRoleMenu;
import com.cs.system.service.SysRoleMenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 角色和菜单关联表 接口定义
 * @author wind
 * @date 2025/08/08 17:52:02
 * @version V1.0
 */
@RestController
@RequestMapping("/api/sysRoleMenu")
public class SysRoleMenuController {

    private final Logger logger = LoggerFactory.getLogger(SysRoleMenuController.class);

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    /**
     * 添加记录接口
     * @param r
     * @return
     */
    @PostMapping("/")
    public R save(@RequestBody SysRoleMenu r) {
        logger.info("SysRoleMenuController.save param: r is {}", r);
        boolean flag = sysRoleMenuService.save(r);
		return HttpCode.flag(flag);
    }


	
	/**
     * 删除记录接口
     * @param r
     * @return
     */
    @DeleteMapping("/")
    public R delete(@RequestBody SysRoleMenu r) {
        logger.info("SysRoleMenuController.delete param: r is {}", r);
        boolean flag = sysRoleMenuService.remove(QueryWrapper.create(r));
        return HttpCode.flag(flag);
    }


    /**
     * 批量查询记录接口
     * @param r
     * @return
     */
    @PostMapping("/list")
    public R list(@RequestBody SysRoleMenu r) {
        logger.info("SysRoleMenuController.list param: r is {}", r);
        List<SysRoleMenu> list = sysRoleMenuService.list(QueryWrapper.create(r));
        return HttpCode.success(list);
    }

    /**
     * 分页查询记录接口
     * @param r
     * @return
     */
    @PostMapping("/page/list")
    public R pageList(@RequestBody SysRoleMenu r){
        logger.info("SysRoleMenuController.pageList param: r is {}", r);
        Page<SysRoleMenu> page = Page.of(r.getPage(), r.getSize());
        sysRoleMenuService.page(page, QueryWrapper.create(r));
        return HttpCode.success(PageVO.of(page));
    }
}
